/**
 * Created by dukes on 2015/10/28.
 */
//module game{
    class DecBuyItemRender extends eui.ItemRenderer{
        public constructor(){
            super();
            this.skinName = "pet.DecorateBuyRenderSkin";
        }
        private img_icon:eui.Image;
        private img_money:eui.Image;
        private img_no:eui.Image;
        private group_cost:eui.BitmapLabel;
        public partAdded(name:string, instance:any){
            super.partAdded(name, instance);
            if( name =="img_icon" ){
                this.img_icon = instance;
            }else if( name =="img_icon" ){
                this.img_icon = instance;
            }else if( name =="img_money" ){
                this.img_money = instance;
            }else if( name =="img_no" ){
                this.img_no = instance;
                this.img_no.addEventListener(egret.TouchEvent.TOUCH_TAP, this.deleteFromSource, this);
            }else if( name =="group_cost" ){
                this.group_cost = instance;
            }
        }

        public dataChanged(){
            super.dataChanged();
            var good:GoodInfo = Model.GetDecorateById(this.data);
            var num;
            var url;
            if( good.byDiamond){
                num = good.price;
                url = "img_diamond";
            }else if(good.bySproutPoint){
                num = good.disPrice;
                url = "meng_point";
            }else{
                num = good.hair;
                if( good.byCatHair && Model.me.myType == Model.GOOD_TYPE_CAT){
                    url = "img_money_cat" ;
                }else if( good.byDogHair && Model.me.myType == Model.GOOD_TYPE_DOG){
                    url = "img_money_dog";
                }else{
                    url = good.byCatHair ? "img_money_cat" : "img_money_dog";
                }
            }
            this.group_cost.text = GetNumString(num,false,true);
            //GetUIAssetsNum(num,this.group_cost);
            this.img_money.source = url;
            this.img_icon.source = GameConst.Res_Root+"resource/assets/decorates/"+good.id+(good.classify != 4 ? ".png" :"-1.jpg");
        }

        public deleteFromSource(evt:egret.TouchEvent){
            DecorateBuyPanel.getInstance().deleteItemByIndex(this.itemIndex);
            DecorateScene.getInstance().takeoff(this.data);
        }
    }
//}